home *** CD-ROM | disk | FTP | other *** search
- ;void wrap_string(strg,return_strg,length);
- ; char *strg,*return_strg;
- ; unsigned short length;
-
- EXTRN _memory_model:byte
-
- _TEXT SEGMENT BYTE PUBLIC 'CODE'
- ASSUME CS:_TEXT
- PUBLIC _wrap_string
- _wrap_string proc near
- cld ;direction flag forward
- push bp ;
- mov bp,sp ;set stack frame
- push di ;
- push si ;
- push ds ;
- cmp _memory_model,0 ;near or far?
- jle begin ;jump if near
- inc bp ;else add 2 to BP
- inc bp ;
- begin: cmp _memory_model,2 ;data near or far?
- jb L0 ;jump if near
- lds si,dword ptr[bp+4] ;DS:SI pts to Strg
- les di,dword ptr[bp+8] ;ES:DI pts to return string
- add bp,4 ;adjust pointer
- jmp short L1 ;jump ahead
- L0: mov si,[bp+4] ;near case
- mov di,[bp+6] ;
- mov ax,ds ;ES = DS
- mov es,ax ;
- L1: mov byte ptr es:[di],0 ;return null if error
- cmp byte ptr [si],0 ;null string?
- je L9 ;quit if so
- L2: push si ;save start positions
- push di ;
- cld ;direction forward
- sub cx,cx ;CX counts length
- L3: lodsb ;copy entire string over
- stosb ;
- inc cx ;inc length counter
- or al,al ;null?
- jne L3 ;loop if not
- pop di ;restore pointers
- pop si ;
- mov bx,[bp+8] ;get line length
- cmp bx,cx ;is it in range?
- jna L4 ;jump if in range
- mov byte ptr[si],0 ;set source string to null
- jmp short L9 ;go quit program
- L4: add di,bx ;point to end-point
- dec di ;adjust to count from zero
- mov cx,[bp+8] ;get line length
- inc cx ;adjust
- cmp byte ptr es:[di+1],0 ;exact length required?
- jne L5 ;jump ahead if not
- mov byte ptr [si],0 ;else make source string null
- jmp short L9 ;all done, go quit
- L5: cmp byte ptr es:[di+1],32 ;next char is a space?
- je L7 ;jump ahead if so
- mov cx,[bp+8] ;get line length
- L6: cmp byte ptr es:[di],32 ;space char?
- je L7 ;quit when find one
- dec di ;pull pointer back one
- dec cx ;dec length counter
- jmp short L6 ;loop
- L7: mov byte ptr es:[di+1],0 ;place terminating null
- mov di,si ;point ES:DI to source
- mov ax,ds ;
- mov es,ax ;
- add si,cx ;point SI to transfer point
- L8: lodsb ;shift down remaining chars
- stosb ;
- or al,al ;null char yet?
- jne L8 ;loop
- L9: pop ds ;
- pop si ;
- pop di ;
- pop bp ;
- cmp _memory_model,0 ;quit
- jle quit ;
- db 0CBh ;RET far
- quit: ret ;RET near
- _wrap_string ENDP
- _TEXT ENDS
- END